<template>
  <div class="app-container">
    <el-card class="box-card">
      <h3>{{$t('进货详情')}}</h3> <el-button @click="getDetail">{{$t('刷新步骤')}}</el-button>
      <el-steps :active="getStepStatus(orderDetail.orderStatus)" finish-status="success" :process-status="getStepProcessStatus(orderDetail.orderStatus)" align-center style="margin-top: 20px">
        <el-step :title="getStatusTitle(1)" :description="$t('调货待处理')" ></el-step>
        <el-step :title="getStatusTitle(2)" :description="$t('同意调货｜拒绝调货')"></el-step>
        <el-step :title="getStatusTitle(3)" :description="$t('审核通过｜审核驳回')"></el-step>
        <el-step :title="getStatusTitle(4)" :description="$t('同意发货｜拒绝发货')"></el-step>
        <el-step :title="getStatusTitle(5)" :description="$t('确认收货｜拒绝收货')"></el-step>
      </el-steps>
<!--      <div v-if="orderDetail.orderStatus != 6">
        <el-steps :active="formatStepStatus(orderDetail.orderStatus)" finish-status="success" align-center>
          <el-step :title="$t('申请调货')"/>
          <el-step :title="$t('同意调货')" />
          <el-step title="总部审核" />
          &lt;!&ndash;          <el-step title="支付付款" />&ndash;&gt;
          <el-step :title="$t('erp处理发货')" />
          <el-step :title="$t('Receive_confirm')" />
        </el-steps>
      </div>
      <div v-else>
        <el-steps :active="6" finish-status="error" align-center>
          <el-step :title="$t('申请调货')"/>
          <el-step :title="$t('同意调货')" />
&lt;!&ndash;          <el-step title="支付付款" />&ndash;&gt;
          <el-step :title="$t('erp处理发货')" />
          <el-step :title="$t('Receive_confirm')" />
          <el-step :title="$t('Denied')"/>
        </el-steps>
      </div>-->

      <div class="table-layout" align="center">
        <el-row>
          <el-col :span="6" class="table-cell-name">{{$t('服务单号')}}</el-col>
          <el-col :span="18" align="left" class="table-cell-content">
            {{orderDetail.orderSn}}
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6" class="table-cell-name">{{$t('Request_status')}}</el-col>
          <el-col :span="18" align="left" class="table-cell-content">
            {{orderStatusMap[orderDetail.orderStatus]}}
          </el-col>
        </el-row>
<!--        <el-row>
          <el-col :span="6" class="table-cell-name">货物编号</el-col>
          <el-col :span="18" align="left" class="table-cell-content">
            {{}}
          </el-col>
        </el-row>-->
        <el-row>
          <el-col :span="6" class="table-cell-name">{{$t('Request_time')}}</el-col>
          <el-col :span="18" align="left" class="table-cell-content">
            {{orderDetail.addTime}}
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6" class="table-cell-name">{{$t('Member_account')}}</el-col>
          <el-col :span="18" align="left" class="table-cell-content">
            {{orderDetail.username}}
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6" class="table-cell-name">{{$t('联系人')}}</el-col>
          <el-col :span="18" align="left" class="table-cell-content">
            {{orderDetail.consignee}}
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6" class="table-cell-name">{{$t('Contact_number')}}</el-col>
          <el-col :span="18" align="left" class="table-cell-content">
            {{orderDetail.mobile}}
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6" class="table-cell-name">{{$t('Store_location')}}</el-col>
          <el-col :span="18" align="left" class="table-cell-content">
            {{orderDetail.shopName}}
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6" class="table-cell-name">{{$t('订货描述')}}</el-col>
          <el-col :span="18" align="left" class="table-cell-content">
            {{orderDetail.orderRemark ? orderDetail.orderRemark : "&nbsp;" }}
          </el-col>
        </el-row>
      </div>

      <div style="margin-top: 20px">
        <svg-icon icon-class="marker" style="color: #606266"/>
        <span class="font-small">{{$t('货品信息')}}</span>
      </div>
      <div class="table-layout">
        <el-table v-loading="listLoading" :data="merchandises" :element-loading-text="$t('Searching')" border fit highlight-current-row>
          <el-table-column align="center" :label="$t('Merchandise_number')" prop="merchandiseSn"/>
          <el-table-column align="center" :label="$t('Product_name')" prop="merchandiseName"/>
<!--          <el-table-column align="center" :label="$t('Merchandise_picture')" prop="addTime">
            <template slot-scope="scope">
              <img :src="scope.row.picUrl" width="40">
            </template>
          </el-table-column>-->
          <el-table-column align="center" :label="$t('Specifications')" prop="standard"/>
          <el-table-column align="center" :label="$t('Model')" prop="model"/>
          <el-table-column align="center" :label="$t('Product_unit')" prop="unit"/>
          <el-table-column align="center" :label="$t('Price')" prop="price">
            <template slot-scope="scope">
              {{toFixed(scope.row.price)}}
            </template>
            </el-table-column>

          <el-table-column align="center" :label="$t('货品信息')" prop="number" v-if="orderDetail.orderStatus != 4"/>
          <el-table-column align="center" :label="$t('订货数量')" v-if="orderDetail.orderStatus == 4" width="180">
              <template slot-scope="scope">
                <el-input-number :min="0" v-model="scope.row.number" @change="changeNumber" style="width: 150px;"></el-input-number>
              </template>
          </el-table-column>

          <el-table-column align="center" :label="$t('Subtotal_')">
            <template slot-scope="scope">
              {{toFixed(scope.row.price*scope.row.number)}}
            </template>
          </el-table-column>
        </el-table>
      </div>

      <el-row>
        <el-col :span="6" :offset="18"><div class="grid-content bg-purple">{{$t('合计')}}：{{orderDetail.orderPrice}}</div></el-col>
      </el-row>

      <!-- <div class="table-layout" v-if="orderDetail.orderStatus == 1">
        <el-form style="margin-top: 10px;">
          <el-form ref="passForm" :model="passForm" label-width="150px">
            <el-form-item label="处理备注" prop="mobile">
              <el-input v-model="passForm.handleRemark" type="textarea"/>
            </el-form-item>
          </el-form>
        </el-form>
      </div> -->

      <div class="table-layout" v-if="orderDetail.orderStatus == 4">
          <el-form style="margin-top: 10px;">
            <el-row>
              <el-form ref="auditForm" label-width="150px">
                <el-col :span="8">
                  <el-form-item :label="$t('优惠率') + '（%）'">
                    <el-input v-model="orderDetail.discount" type="number" @change="changeAuditFormDiscount" />
                  </el-form-item>
                </el-col>

                <el-col :span="8">
                  <el-form-item :label="$t('收款优惠')">
                    <el-input v-model="orderDetail.discountPrice" type="number" @change="changeAuditFormDiscountPrice" />
                  </el-form-item>
                </el-col>

                <el-col :span="8">
                  <el-form-item :label="$t('本次收款')">
                    <el-input v-model="orderDetail.discountLastPrice" type="number" @change="changeAuditFormDiscountLastPrice" />
                  </el-form-item>
                </el-col>

                <el-col :span="24">
                  <el-form-item :label="$t('备注')">
                    <el-input v-model="acceptAuditRemark" type="textarea" />
                  </el-form-item>
                </el-col>
              </el-form>
            </el-row>
          </el-form>
      </div>

      <el-row v-if="orderDetail.orderStatus == 7">
          <el-col :span="8">
              {{$t('优惠率')}}（%）：{{orderDetail.discount}}
          </el-col>

          <el-col :span="8">
              {{$t('收款优惠')}}：{{orderDetail.discountPrice}}
          </el-col>

          <el-col :span="8">
              {{$t('本次收款')}}：{{orderDetail.discountLastPrice}}
          </el-col>
      </el-row>

      <div style="margin-top: 20px">
        <svg-icon icon-class="marker" style="color: #606266"/>
        <span class="font-small">{{$t('处理进度')}}</span>
      </div>

      <div class="table-layout">
        <el-table v-loading="listLoading" :data="merchandiseLogs" :element-loading-text="$t('Searching')" border fit highlight-current-row>
          <el-table-column align="center" :label="$t('Operating_time')" prop="addTime"/>
          <el-table-column align="center" :label="$t('Operator_details')" prop="content"/>
          <el-table-column align="center" :label="$t('Notes')" prop="remark"/>
        </el-table>
      </div>

    </el-card>
    <el-dialog :visible.sync="orderChenkDialog.visible" :title="$t(orderChenkDialog.title)">
      <el-form ref="orderChenkDialog" :model="orderChenkDialog" :rules="orderChenkFormRules" status-icon label-position="left" label-width="150px">
        <el-form-item :label="$t('请输入备注')" prop="remark">
          <el-input type="textarea" v-model="orderChenkDialog.remark"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="orderChenkDialog.visible = false">{{$t('Cancel')}}</el-button>
        <el-button @click="handleOrderChenkSubmit(orderChenkDialog.isChenk)" type="primary">{{$t('Confirm')}}</el-button>
      </div>
    </el-dialog>
    <el-dialog :visible.sync="orderPassDialogVisible" :title="$t('同意调货')">
      <el-form ref="orderPassForm" :model="orderPassForm" :rules="orderPassFormRules" status-icon label-position="left" label-width="150px">
        <el-form-item :label="$t('请输入备注')" prop="remark">
          <el-input type="textarea" v-model="orderPassForm.remark"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="orderPassDialogVisible = false">{{$t('Cancel')}}</el-button>
        <el-button @click="handleOrderPassSubmit" type="primary">{{$t('Confirm')}}</el-button>
      </div>
    </el-dialog>

    <el-dialog :visible.sync="orderNoPassDialogVisible" :title="$t('拒绝调货')">
      <el-form ref="orderNoPassForm" :model="orderNoPassForm" :rules="orderNoPassFormRules" status-icon label-position="left" label-width="150px">
        <el-form-item label="请输入备注" prop="remark">
          <el-input type="textarea" v-model="orderNoPassForm.remark"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="orderNoPassDialogVisible = false">{{$t('Cancel')}}</el-button>
        <el-button @click="handleOrderNoPassSubmit" type="primary">{{$t('Confirm')}}</el-button>
      </div>
    </el-dialog>

    <el-dialog :visible.sync="orderReceivingAuditPassDialogVisible" :title="$t('同意收货')">
      <el-form ref="orderReceivingAuditPassForm" :model="orderReceivingAuditPassForm" :rules="orderReceivingAuditPassFormRules" status-icon label-position="left" label-width="150px">
        <el-form-item :label="$t('请输入备注')" prop="remark">
          <el-input type="textarea" v-model="orderReceivingAuditPassForm.remark"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="orderReceivingAuditPassDialogVisible = false">{{$t('Cancel')}}</el-button>
        <el-button @click="handleReceivingAuditPassSubmit" type="primary">{{$t('Confirm')}}</el-button>
      </div>
    </el-dialog>

    <el-dialog :visible.sync="orderReceivingNoAuditPassDialogVisible" :title="$t('拒绝收货收货')">
      <el-form ref="orderReceivingNoAuditPassForm" :model="orderReceivingNoAuditPassForm" :rules="orderReceivingNoAuditPassFormRules" status-icon label-position="left" label-width="150px">
        <el-form-item :label="$t('请输入备注')" prop="remark">
          <el-input type="textarea" v-model="orderReceivingNoAuditPassForm.remark"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="orderReceivingNoAuditPassDialogVisible = false">{{$t('Cancel')}}</el-button>
        <el-button @click="handleReceivingNoAuditPassSubmit" type="primary">{{$t('Confirm')}}</el-button>
      </div>
    </el-dialog>

    <div class="op-container" style="margin-top: 20px;">
      <el-button @click="handleCancel">{{$t('返回')}}</el-button>
<!--      <el-button v-if="orderDetail.orderStatus == 2" type="primary" @click="handleOrderPay">{{$t('支付货款')}}</el-button>-->
      <el-button v-if="orderDetail.orderStatus == 2" v-permission="['GET /admin/p/stock_stockin_apply']" type="primary" @click="handleOrderCheck">{{$t('审核通过')}}</el-button>
      <el-button v-if="orderDetail.orderStatus == 2" v-permission="['GET /admin/p/stock_stockin_apply']" type="danger" @click="handleOrderNoCheck">{{$t('审核驳回')}}</el-button>

      <el-button v-if="orderDetail.orderStatus == 1" v-permission="['GET /admin/p/stock_stockin_apply']" type="primary" @click="handleOrderPass">{{$t('同意调货')}}</el-button>
      <el-button v-if="orderDetail.orderStatus == 1" v-permission="['GET /admin/p/stock_stockin_apply']" type="danger" @click="handleOrderNoPass">{{$t('拒绝调货')}}</el-button>

<!--      <el-button v-if="orderDetail.orderStatus == 4" v-permission="['GET /admin/p/stock_stockin_submittakeapply']" v-shop="true" type="primary" @click="handleAcceptAudit">{{$t('提交收货审核')}}</el-button>-->
<!--       <el-button v-if="orderDetail.orderStatus == 4" v-shop="true" type="primary" @click="handleTakeDelivery">确认收货</el-button>-->
      <el-button v-if="orderDetail.orderStatus == 4" v-permission="['GET /admin/p/stock_stockin_takeapply']" type="primary" @click="handleReceivingAuditPass">{{$t('收货完成')}}</el-button>
      <el-button v-if="orderDetail.orderStatus == 4" v-permission="['GET /admin/p/stock_stockin_takeapply']" type="danger" @click="handleReceivingNoAuditPass">{{$t('拒绝收货')}}</el-button>
    </div>
  </div>
</template>

<script>
import {shopOrderDetail, shopOrderPass,orderHqPass,orderHqNoPass, shopOrderNoPass, shopOrderPay, shopDeliverGoods,
   shopCancelDeliverGoods, shopTakeDelivery, merchandiseNumber, acceptAudit, passAudit, noPassAudit} from '@/api/shop'
import {materialApply} from '@/api/erp'
import { MessageBox } from 'element-ui'

export default {
  name: 'ShopOrderDetail',
  data() {
    const orderStatusMap = {
      1: this.$t('待调货'),
      2: this.$t('待审核'),
      3: this.$t('待发货'),
      4: this.$t('待收货'),
      5: this.$t('已收货'),
      6: this.$t('拒绝调货'),
      7: this.$t('审核驳回'),
      8: this.$t('拒绝发货'),
      9: this.$t('拒绝收货'),
    }

    const validateDouble = (rule, value, callback) => {
      if (!/^[0-9,.]*$/.test(value)) {
        callback(new Error(this.$t('运费价格必须为数字')))
      } else {
        callback()
      }
    }
    return {
      listLoading:true,
      orderStatusMap,
      validateDouble,
      orderId:undefined,
      orderDetail: {
      },
      merchandises:[],
      merchandiseLogs: [],
      passForm:{
        shipPrice:undefined,
        handleRemark:undefined
      },
      passRules: {
        number: [
          { shipPrice: true, message: this.$t('申请数量不能为空'), trigger: 'change' },
          { validator: validateDouble, message: this.$t('申请数量不能为非数字'), trigger: 'change' }
        ],
        userId: [{ required: true, message: this.$t('联系人不能为空'), trigger: 'blur' }]
      },
      orderChenkDialog:{
        visible:false,
        remark:undefined,
        title:undefined,
        isChenk:undefined
      },
      acceptAuditRemark: '',
      orderPassDialogVisible: false,
      orderPassForm: {
        remark: undefined
      },
      orderPassFormRules: {
        remark: [{ required: true, message: this.$t('备注不能为空'), trigger: 'blur' }]
      },
      orderChenkFormRules: {
        remark: [{ required: true, message: this.$t('备注不能为空'), trigger: 'blur' }]
      },
      orderNoPassDialogVisible: false,
      orderNoPassForm: {
        remark: undefined
      },
      orderNoPassFormRules: {
        remark: [{ required: true, message: this.$t('备注不能为空'), trigger: 'blur' }]
      },
      orderReceivingAuditPassDialogVisible: false,
      orderReceivingAuditPassForm: {
        remark: undefined
      },
      orderReceivingAuditPassFormRules: {
        remark: [{ required: true, message: this.$t('备注不能为空'), trigger: 'blur' }]
      },
      orderReceivingNoAuditPassDialogVisible: false,
      orderReceivingNoAuditPassForm: {
        remark: undefined
      },
      orderReceivingNoAuditPassFormRules: {
        remark: [{ required: true, message: this.$t('备注不能为空'), trigger: 'blur' }]
      }
    }
  },
  filters: {
    hasNumber: async function(row){

    }
  },
  created(){
    if(this.$route.query.id){
      this.orderId = this.$route.query.id
    }
    this.getDetail()
  },
  methods: {
    toFixed(val){
      return val.toFixed(2);
    },
    getDetail(){
      shopOrderDetail(this.orderId).then(res=>{
        this.listLoading = false
        this.orderDetail = res.data.data.order
        this.merchandises = res.data.data.merchandises
        this.merchandiseLogs = res.data.data.merchandiseLogs

        this.merchandises.forEach(merchandise=>{
          let queryParam = {
            shopId: this.orderDetail.shopId,
            merchandiseId: merchandise.merchandiseId
          }
          merchandiseNumber(queryParam).then(res=>{
            merchandise.store = res.data.data
          })
        })
      })
    },
    // lumiere咖啡

    getStepStatus(value) {
        if (value === 1) {
            // 申请调货
            return 0
        } else if (value === 2 || value === 6) {
            // 同意调货
            return 1
        } else if ( value === 3 || value === 7) {
            // 总部审核
            return 2
        } else if (value === 4 || value === 8) {
            // erp处理发货
            return 3
        } else if(value === 5 || value === 9){
            // 确认收货
            return 4
        }
    },
    getStepProcessStatus(orderStatus) {
      const statusList = [6, 7, 8, 9];
      if (statusList.includes(orderStatus)) {
        return 'error';
      }
      return 'success'; // 这里假设除了指定的几个值为error外，其他情况返回默认等待状态，你可以根据实际需求调整
    },
    getStatusTitle(stepIndex) {
        const currentStatus = this.orderDetail.orderStatus;
        switch (stepIndex) {
            case 1:
                return this.$t('已申请调货');
            case 2:
                if (currentStatus === 2) {
                    return this.$t('同意调货');
                } else if (currentStatus === 6) {
                    return this.$t('拒绝调货');
                } else if (currentStatus > 2 && currentStatus!== 6) {
                    return this.$t('同意调货（待审核）');
                } else {
                    return this.$t('同意调货（待审核）');
                }
            case 3:
                if (currentStatus === 3) {
                    return this.$t('审核通过');
                } else if (currentStatus === 7) {
                    return this.$t('审核驳回');
                } else if (currentStatus > 3 && currentStatus!== 7) {
                    return this.$t('总部审核（待处理）');
                } else {
                    return this.$t('总部审核（待处理）');
                }
            case 4:
                if (currentStatus === 4) {
                    return this.$t('erp已发货');
                } else if (currentStatus === 8) {
                    return this.$t('拒绝发货');
                } else if (currentStatus > 4 && currentStatus!== 8) {
                    return this.$t('erp处理发货（待发货）');
                } else {
                    return this.$t('erp处理发货（待发货）');
                }
            case 5:
                if (currentStatus === 5) {
                    return this.$t('确认收货');
                } else if (currentStatus === 9) {
                    return this.$t('拒绝收货');
                } else if (currentStatus > 5 && currentStatus!== 9) {
                    return this.$t('确认收货（待确认）');
                } else {
                    return this.$t('确认收货（待确认）');
                }
            default:
                return '';
        }
    },

    formatStepStatus(value) {
      if (value === 2) {
        // 支付
        return 2
      } else if (value === 3 || value === 7) {
        // 处理发货
        return 2
      } else if ( value === 10) {
        // 审核成功
        return 3
      } else if (value === 4) {
        // 确认发货
        return 4
      } else if(value === 8){
        // 确认收货
        return 4
      } else {
        // 同意调货、拒绝调货
        return 1
      }
    },
    handleCancel(){
      this.$router.push({path:'/repository/list'})
    },
    // 审核通过
    handleOrderCheck(){
      this.orderChenkDialog={
        visible : true,
        remark : '',
        title :  '审核通过',
        isChenk : true,
      }

    },
    // 审核不通过
    handleOrderNoCheck(){
      this.orderChenkDialog={
        visible : true,
        remark : '',
        title :  '审核不通过',
        isChenk : false,
      }
    },
    // 点击同意
    handleOrderChenkSubmit(){
      const id = this.orderDetail.id
      const remark = this.orderChenkDialog.remark


      this.$refs['orderChenkDialog'].validate(valid => {
        if (valid) {
          if(this.orderChenkDialog.isChenk){
            orderHqPass(id, remark).then(response => {
            this.$notify.success({
              title: this.$t('Success!'),
              message: '处理成功'
            })
            this.$router.push({ path: '/repository/merchandise/list' })
          })
          .catch(response => {
            MessageBox.alert(this.$t('Error') + this.$t(response.data.errmsg), this.$t('Warning'), {
              confirmButtonText: this.$t('Confirm'),
              type: 'error'
            })
          })
          }else{
            orderHqNoPass(id, remark).then(response => {
            this.$notify.success({
              title: this.$t('Success!'),
              message: '处理成功'
            })
            this.$router.push({ path: '/repository/list' })
          })
          .catch(response => {
            MessageBox.alert(this.$t('Error') + this.$t(response.data.errmsg), this.$t('Warning'), {
              confirmButtonText: this.$t('Confirm'),
              type: 'error'
            })
          })
          }

        }
      })
    },
    handleOrderPass(){
      this.orderPassDialogVisible = true
      this.orderPassForm.remark = ''
    },
    handleOrderPassSubmit(title){
      const id = this.orderDetail.id
      const remark = this.orderPassForm.remark
      this.$refs['orderPassForm'].validate(valid => {
        if (valid) {
          shopOrderPass(id, remark).then(response => {
            this.$notify.success({
              title: this.$t('Success!'),
              message: '处理成功'
            })
            this.$router.push({ path: '/repository/merchandise/list' })
          })
          .catch(response => {
            MessageBox.alert(this.$t('Error') + this.$t(response.data.errmsg), this.$t('Warning'), {
              confirmButtonText: this.$t('Confirm'),
              type: 'error'
            })
          })
        }
      })
    },
    handleOrderNoPass(){
      this.orderNoPassDialogVisible = true
      this.orderNoPassForm.remark = ''
    },
    handleOrderNoPassSubmit(){
      const id = this.orderDetail.id
      const remark = this.orderNoPassForm.remark
      this.$refs['orderNoPassForm'].validate(valid => {
        if (valid) {
          shopOrderNoPass(id, remark).then(response => {
            this.$notify.success({
              title: this.$t('Success!'),
              message: '处理成功'
            })
            this.$router.push({ path: '/repository/list' })
          })
          .catch(response => {
            MessageBox.alert(this.$t('Error') + this.$t(response.data.errmsg), this.$t('Warning'), {
              confirmButtonText: this.$t('Confirm'),
              type: 'error'
            })
          })
        }
      })
    },
    handleOrderPay(){
      this.passForm.adminOrderId = this.orderDetail.id
      shopOrderPay(this.passForm).then(response => {
        this.$notify.success({
          title: this.$t('Success!'),
          message: '处理成功'
        })
        this.$router.push({ path: '/repository/list' })
      })
      .catch(response => {
        MessageBox.alert(this.$t('Error') + this.$t(response.data.errmsg), this.$t('Warning'), {
          confirmButtonText: this.$t('Confirm'),
          type: 'error'
        })
      })
    },
    handleDeliverGoods(){
      this.passForm.adminOrderId = this.orderDetail.id
      shopDeliverGoods(this.passForm).then(response => {
        this.$notify.success({
          title: this.$t('Success!'),
          message: '处理成功'
        })
        this.$router.push({ path: '/repository/list' })
      })
      .catch(response => {
        MessageBox.alert(this.$t('Error') + this.$t(response.data.errmsg), this.$t('Warning'), {
          confirmButtonText: this.$t('Confirm'),
          type: 'error'
        })
      })
    },
    handleCancelDeliverGoods(){
      this.passForm.adminOrderId = this.orderDetail.id
      shopCancelDeliverGoods(this.passForm).then(response => {
        this.$notify.success({
          title: this.$t('Success!'),
          message: '处理成功'
        })
        this.$router.push({ path: '/repository/list' })
      })
      .catch(response => {
        MessageBox.alert(this.$t('Error') + this.$t(response.data.errmsg), this.$t('Warning'), {
          confirmButtonText: this.$t('Confirm'),
          type: 'error'
        })
      })
    },
    handleTakeDelivery(){
      this.passForm.adminOrderId = this.orderDetail.id
      shopTakeDelivery(this.passForm).then(response => {
        this.$notify.success({
          title: this.$t('Success!'),
          message: '处理成功'
        })
        this.$router.push({ path: '/repository/list' })
      })
      .catch(response => {
        MessageBox.alert(this.$t('Error') + this.$t(response.data.errmsg), this.$t('Warning'), {
          confirmButtonText: this.$t('Confirm'),
          type: 'error'
        })
      })
    },
    changeNumber () {
      let totalAmount = 0
      this.merchandises.forEach(item=>{
        totalAmount = totalAmount + (item.number * item.price)
      })
      this.orderDetail.orderPrice = totalAmount

      this.orderDetail.discount = 0
      this.orderDetail.discountPrice = 0
      this.orderDetail.discountLastPrice = totalAmount
    },
    changeAuditFormDiscount (val) {
      this.orderDetail.discountPrice = this.orderDetail.orderPrice * val / 100;
      this.orderDetail.discountLastPrice = this.orderDetail.orderPrice - this.orderDetail.discountPrice;
    },
    changeAuditFormDiscountPrice (val) {
      this.orderDetail.discount = val / this.orderDetail.orderPrice * 100;
      this.orderDetail.discountLastPrice = this.orderDetail.orderPrice - val;
    },
    changeAuditFormDiscountLastPrice (val) {
      this.orderDetail.discountPrice = this.orderDetail.orderPrice - val;
      this.orderDetail.discount = this.orderDetail.discountPrice / this.orderDetail.orderPrice * 100;
    },
    handleAcceptAudit() {
      let submitMerchandises = [];
      this.merchandises.forEach(item => {
        let p = {
          merchandiseId: item.merchandiseId,
          number: item.number,
          price: item.price
        }
        submitMerchandises.push(p);
      })

      let auditForm = {
        adminOrderId: this.orderDetail.id,
        orderPrice: this.orderDetail.orderPrice,
        discount: this.orderDetail.discount,
        discountPrice: this.orderDetail.discountPrice,
        discountLastPrice: this.orderDetail.discountLastPrice,
        actualPrice: this.orderDetail.discountLastPrice,
        remark: this.acceptAuditRemark,
        merchandises: submitMerchandises
      }

      acceptAudit(auditForm).then(response => {
        this.$notify.success({
          title: this.$t('Success!'),
          message: '处理成功'
        })
        this.$router.push({ path: '/repository/list' })
      })
      .catch(response => {
        MessageBox.alert(this.$t('Error') + this.$t(response.data.errmsg), this.$t('Warning'), {
          confirmButtonText: this.$t('Confirm'),
          type: 'error'
        })
      })
    },
    handleReceivingAuditPass() {
      this.orderReceivingAuditPassDialogVisible = true
      this.orderReceivingAuditPassForm.remark = ''
    },
    handleReceivingAuditPassSubmit(){
      const id = this.orderDetail.id
      const remark = this.orderReceivingAuditPassForm.remark
      this.$refs['orderReceivingAuditPassForm'].validate(valid => {
        if (valid) {
          passAudit(id, remark).then(response => {
            this.$notify.success({
              title: this.$t('Success!'),
              message: '处理成功'
            })
            this.$router.push({ path: '/repository/list' })
          })
          .catch(response => {
            MessageBox.alert(this.$t('Error') + this.$t(response.data.errmsg), this.$t('Warning'), {
              confirmButtonText: this.$t('Confirm'),
              type: 'error'
            })
          })
        }
      })
    },
    handleReceivingNoAuditPass() {
      this.orderReceivingNoAuditPassDialogVisible = true
      this.orderReceivingNoAuditPassForm.remark = ''
    },
    handleReceivingNoAuditPassSubmit() {
      const id = this.orderDetail.id
      const remark = this.orderReceivingNoAuditPassForm.remark

      this.$refs['orderReceivingNoAuditPassForm'].validate(valid => {
        if (valid) {
          noPassAudit(id, remark).then(response => {
            this.$notify.success({
              title: this.$t('Success!'),
              message: '处理成功'
            })
            this.$router.push({ path: '/repository/list' })
          })
          .catch(response => {
            MessageBox.alert(this.$t('Error') + this.$t(response.data.errmsg), this.$t('Warning'), {
              confirmButtonText: this.$t('Confirm'),
              type: 'error'
            })
          })
        }
      })
    }
  }
}
</script>

<style scoped>
  .detail-container {
    width: 80%;
    padding: 20px 20px 20px 20px;
    margin: 20px auto;
  }

  .operate-container {
    background: #F2F6FC;
    height: 80px;
    margin: -20px -20px 0;
    line-height: 80px;
  }

  .operate-button-container {
    float: right;
    margin-right: 20px
  }

  .table-layout {
    margin-top: 20px;
    border-left: 1px solid #DCDFE6;
    border-top: 1px solid #DCDFE6;
  }

  .table-cell {
    height: 60px;
    line-height: 40px;
    border-right: 1px solid #DCDFE6;
    border-bottom: 1px solid #DCDFE6;
    padding: 10px;
    font-size: 14px;
    color: #606266;
    text-align: center;
    overflow: hidden;
  }

  .table-cell-title {
    border-right: 1px solid #DCDFE6;
    border-bottom: 1px solid #DCDFE6;
    padding: 10px;
    background: #F2F6FC;
    text-align: center;
    font-size: 14px;
    color: #303133;
  }

  .table-cell-name {
    border-right: 1px solid #DCDFE6;
    border-bottom: 1px solid #DCDFE6;
    padding: 10px;
    background: #F2F6FC;
    font-size: 14px;
    color: #303133;
  }
  .table-cell-content {
    border-right: 1px solid #DCDFE6;
    border-bottom: 1px solid #DCDFE6;
    padding: 10px;
    font-size: 14px;
    color: #303133;
  }

  .grid-content {
    padding: 10px;
    text-align: right;
  }
</style>
